Skip to content

Prevent duplicate bot comments in auto-answer-issues workflow#5844

Merged
trwalke merged 2 commits intotrwalke/addGhActionForIssuesfrom
copilot/sub-pr-5836-one-more-time
Mar 11, 2026
Merged

Prevent duplicate bot comments in auto-answer-issues workflow#5844
trwalke merged 2 commits intotrwalke/addGhActionForIssuesfrom
copilot/sub-pr-5836-one-more-time

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Mar 11, 2026

The auto-answer-issues workflow triggers on both opened and labeled events, causing the bot to post a new AI-generated comment every time a label is added to an eligible issue.

Changes proposed in this request

  • Before calling Azure OpenAI or posting a comment, fetch all existing issue comments via octokit.paginate and check if github-actions[bot] has already commented
  • If a prior bot comment is detected, log a message and exit early — no token consumption, no duplicate comment
const comments = await octokit.paginate(octokit.issues.listComments, {
  owner: REPO_OWNER,
  repo: REPO_NAME,
  issue_number: issueNumber,
  per_page: 100
});
const botAlreadyCommented = comments.some(
  (comment) => comment.user?.login === "github-actions[bot]"
);
if (botAlreadyCommented) {
  console.log("Bot has already commented on this issue. Skipping.");
  return;
}

Testing

No automated tests applicable for workflow logic. Behavior can be verified by triggering the workflow on an issue that already has a github-actions[bot] comment and confirming no new comment is posted.

Performance impact

Adds one paginated API call per workflow run before any OpenAI call. Negligible impact; saves cost on subsequent triggers by skipping the OpenAI call entirely.

Documentation

  • All relevant documentation is updated.

💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Co-authored-by: trwalke <30090357+trwalke@users.noreply.github.com>
Copilot AI changed the title [WIP] [WIP] Address comments on GitHub Actions workflow for issue auto-answering Prevent duplicate bot comments in auto-answer-issues workflow Mar 11, 2026
@trwalke trwalke marked this pull request as ready for review March 11, 2026 22:29
@trwalke trwalke requested a review from a team as a code owner March 11, 2026 22:29
@trwalke trwalke merged commit 7e8dbfc into trwalke/addGhActionForIssues Mar 11, 2026
2 checks passed
@trwalke trwalke deleted the copilot/sub-pr-5836-one-more-time branch March 11, 2026 22:29
bgavrilMS pushed a commit that referenced this pull request Mar 19, 2026
* Initial plan

* Add duplicate comment detection to auto-answer-issues workflow

Co-authored-by: trwalke <30090357+trwalke@users.noreply.github.com>

---------

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: trwalke <30090357+trwalke@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants